//==========================================================
// 此代码由TilverNET代码生成工具自动生成，请不要修改
// 代码生成器版本号：1.2
// 作者：landy
// 联系方式：(QQ)86566178
// 创建时间：2014/6/21 10:58:22
//==========================================================

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using Tilver.Data;
using Tilver.Data.DataPager;

namespace Weixin.MP.DAL.WeixinMP
{
	#region EO

	/// <summary>
	/// 登录用户 《dbo.Users(实体类)》
	/// </summary>
	[Serializable]
	public class UsersEO : IRowMapper<UsersEO>
	{
		protected bool _hasOriginal = false;
		protected string _userId;
		protected string _originalUserId;
		protected string _password;
		protected string _nickName;
		protected string _phone;
		protected string _email;
		protected DateTime _recTime;
		protected DateTime _loginTime;

		/// <summary>
		/// 主键是否有原始值（即数据库中保存的值），用于实体对象更新时
		/// </summary>
		public bool HasOriginal
		{
			get { return _hasOriginal; }
		}


		/// <summary>
		/// 用户名 《[主键]  [varchar]》
		/// </summary>
		public string UserId
		{
			get { return _userId; }
			set { _userId = value;}
		}

		/// <summary>
		/// 用户名 《数据库中的原始主键值副本》
		/// </summary>
		public string OriginalUserId
		{
			get { return _originalUserId; }
			set { 
				_hasOriginal = true;
				_originalUserId = value;
			}
		}

		/// <summary>
		/// 密码 《[字段]  [varchar]》
		/// </summary>
		public string Password
		{
			get { return _password; }
			set { _password = value;}
		}

		/// <summary>
		/// 昵称 《[字段]  [nvarchar]》
		/// </summary>
		public string NickName
		{
			get { return _nickName; }
			set {
				if (value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for NickName", value, value == null ? "null" : value.ToString());
				_nickName = value;
			}
		}

		/// <summary>
		/// 电话 《[字段]  [varchar]》
		/// </summary>
		public string Phone
		{
			get { return _phone; }
			set { _phone = value;}
		}

		/// <summary>
		/// 邮箱地址 《[字段]  [varchar]》
		/// </summary>
		public string Email
		{
			get { return _email; }
			set { _email = value;}
		}

		/// <summary>
		/// 创建时间 《[字段]  [datetime]》
		/// </summary>
		public DateTime RecTime
		{
			get { return _recTime; }
			set { _recTime = value;}
		}

		/// <summary>
		/// 最后一次登录时间 《[字段]  [datetime]》
		/// </summary>
		public DateTime LoginTime
		{
			get { return _loginTime; }
			set { _loginTime = value;}
		}

		/// <summary>
		/// 默认构造函数
		/// </summary>
		public UsersEO() 
		{
			UserId = string.Empty;
			Password = string.Empty;
			RecTime = DateTime.Now;
			LoginTime = DateTime.Now;
		}

		/// <summary>
		/// 自定义构造函数
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name = "password">密码</param>
		/// <param name = "nickName">昵称</param>
		/// <param name = "phone">电话</param>
		/// <param name = "email">邮箱地址</param>
		/// <param name = "recTime">创建时间</param>
		/// <param name = "loginTime">最后一次登录时间</param>
		public UsersEO(string userId, string password, string nickName, string phone, string email, DateTime recTime, DateTime loginTime) 
		{
			_userId = userId;
			_password = password;
			_nickName = nickName;
			_phone = phone;
			_email = email;
			_recTime = recTime;
			_loginTime = loginTime;
		}


		/// <summary>
		/// 将结果集映射成实体对象
		/// </summary>
		/// <param name = "reader">只进结果集流</param>
		/// <return></return>
		public UsersEO MapRow(IDataReader reader)
		{
			var ret = new UsersEO();
			ret.UserId = (string)reader["UserId"];
			ret.OriginalUserId = ret.UserId;
			ret.Password = (string)reader["Password"];
			ret.NickName = (reader["NickName"] is DBNull) ? null : (string)reader["NickName"];
			ret.Phone = (reader["Phone"] is DBNull) ? null : (string)reader["Phone"];
			ret.Email = (reader["Email"] is DBNull) ? null : (string)reader["Email"];
			ret.RecTime = (DateTime)reader["RecTime"];
			ret.LoginTime = (DateTime)reader["LoginTime"];
			return ret;
		}

		/// <summary>
		/// 将结果集映射成实体对象，返回映射方法
		/// </summary>
		/// <return></return>
		public Func<IDataReader, UsersEO> GetMapper()
		{
			return MapRow;
		}


	}


	#endregion
	#region MO

	/// <summary>
	/// 登录用户 《dbo.Users(逻辑类)》
	/// </summary>
	public class UsersMO : DbManagerBase
	{

		#region 构造函数
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "routeData">路由数据</param>
		public UsersMO(object routeData = null) : base(routeData) { }

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "connectionStringName">连接字符串名称</param>
		public UsersMO(string connectionStringName) : base(connectionStringName) { }

		#endregion

		#region 私有方法
		/// <summary>
		/// 数据库访问操作方法
		/// </summary>
		/// <param name = "sql">SQL语句</param>
		/// <return>返回数据操作对象</return>
		private DbAdoBase AdoBase(string sql)
		{
			return DataBase.CreateDbAdo(sql, CommandType.Text);
		}

		#endregion

		#region Select方法集合
		/// <summary>
		/// 按主键查询
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public UsersEO SelectByPK(string userId, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] WHERE [UserId]=@UserId ");
			return AdoBase(sql.ToString())
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteReader(tm).MapToSingle(new UsersEO().GetMapper());
		}


		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<UsersEO> SelectByUserId(string userId, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] WHERE [UserId]=@UserId");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteList(new UsersEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "password">密码</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<UsersEO> SelectByPassword(string password, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] WHERE [Password]=@Password");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@Password", password, DbType.AnsiString, 100)
							.ExecuteList(new UsersEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "nickName">昵称</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<UsersEO> SelectByNickName(string nickName, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] WHERE [NickName]=@NickName");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@NickName", nickName, DbType.String, 50)
							.ExecuteList(new UsersEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "phone">电话</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<UsersEO> SelectByPhone(string phone, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] WHERE [Phone]=@Phone");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@Phone", phone, DbType.AnsiString, 20)
							.ExecuteList(new UsersEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "email">邮箱地址</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<UsersEO> SelectByEmail(string email, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] WHERE [Email]=@Email");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@Email", email, DbType.AnsiString, 100)
							.ExecuteList(new UsersEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "recTime">创建时间</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<UsersEO> SelectByRecTime(DateTime recTime, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] WHERE [RecTime]=@RecTime");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@RecTime", recTime, DbType.DateTime, 8)
							.ExecuteList(new UsersEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "loginTime">最后一次登录时间</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<UsersEO> SelectByLoginTime(DateTime loginTime, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] WHERE [LoginTime]=@LoginTime");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@LoginTime", loginTime, DbType.DateTime, 8)
							.ExecuteList(new UsersEO().GetMapper(), tm);
		}

		/// <summary>
		/// 按自定义条件查询
		/// </summary>
		/// <param name = "where">自定义条件,where子句</param>
		/// <param name = "top">获取行数</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<UsersEO> Select(string where, int top, string sort, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users] ");
			if (!string.IsNullOrEmpty(where)) format.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddParameters(paras)
							.ExecuteList(new UsersEO().GetMapper(), tm);
		}

		/// <summary>
		/// 分页查询
		/// </summary>
		/// <param name = "where">条件表达式</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">传入参数</param>
		/// <param name = "pageSize">页大小</param>
		/// <param name = "pageIndex">页码</param>
		/// <param name = "recordCount">总记录数，由于计算总记录数影响数据库性能，只有小于或等于0的情况下才返回总记录数</param>
		/// <return>分页数据</return>
		public List<UsersEO> SelectPager(string where, string sort, IList<DbParameter> paras, long pageSize, long pageIndex, ref long recordCount)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime] FROM [dbo].[Users]");
			if (!string.IsNullOrEmpty(where)) sql.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) sql.AppendFormat(" ORDER BY {0} ", sort);
			var pager = this.DataBase.CreatePager(sql.ToString(), pageSize, "UserId");
			pager.AddParameters(paras);
			if (recordCount <= 0)
			{
				recordCount = pager.GetRecordCount();
			}
			return pager.GetPageData(pageIndex).MapToList(new UsersEO().GetMapper());
		}

		#endregion

		#region Insert方法集合
		/// <summary>
		/// 插入数据，有自增列时，item中自增字段为新增值，否则，返回影响的行数
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "item">要插入的实体对象</param>
		/// <return></return>
		public int Insert(UsersEO item, TransactionManager tm = null)
		{
			const string sql = @"INSERT INTO [dbo].[Users] ([UserId], [Password], [NickName], [Phone], [Email], [RecTime], [LoginTime]) VALUES (@UserId, @Password, @NickName, @Phone, @Email, @RecTime, @LoginTime) ";
			return AdoBase(sql)
												.AddInParameter("@UserId", item.UserId, DbType.AnsiString, 20)
												.AddInParameter("@Password", item.Password, DbType.AnsiString, 100)
												.AddInParameter("@NickName", item.NickName != null ?  (object)item.NickName : DBNull.Value, DbType.String, 50)
												.AddInParameter("@Phone", item.Phone != null ?  (object)item.Phone : DBNull.Value, DbType.AnsiString, 20)
												.AddInParameter("@Email", item.Email != null ?  (object)item.Email : DBNull.Value, DbType.AnsiString, 100)
												.AddInParameter("@RecTime", item.RecTime, DbType.DateTime, 8)
												.AddInParameter("@LoginTime", item.LoginTime, DbType.DateTime, 8)
												.ExecuteNonQuery(tm);
		}
		#endregion

		#region Update方法集合
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "item">要更新的实体对象</param>
		/// <param name = "tm">事务管理对象</param>
		/// <return></return>
		public int Update(UsersEO item, TransactionManager tm = null)
		{
		if (item.UserId == null) throw new ArgumentNullException("属性UserId不能为null.");
		if (item.Password == null) throw new ArgumentNullException("属性Password不能为null.");
			const string sql = @"UPDATE [dbo].[Users] SET [UserId]=@UserId, [Password]=@Password, [NickName]=@NickName, [Phone]=@Phone, [Email]=@Email, [RecTime]=@RecTime, [LoginTime]=@LoginTime WHERE [UserId]=@OriginalUserId";
			return AdoBase(sql)
							.AddInParameter("@OriginalUserId", (item.HasOriginal) ? item.OriginalUserId : item.UserId, DbType.AnsiString, 20)
							.AddInParameter("@UserId", item.UserId, DbType.AnsiString, 20)
							.AddInParameter("@Password", item.Password, DbType.AnsiString, 100)
							.AddInParameter("@NickName", item.NickName != null ?  (object)item.NickName : DBNull.Value, DbType.String, 50)
							.AddInParameter("@Phone", item.Phone != null ?  (object)item.Phone : DBNull.Value, DbType.AnsiString, 20)
							.AddInParameter("@Email", item.Email != null ?  (object)item.Email : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@RecTime", item.RecTime, DbType.DateTime, 8)
							.AddInParameter("@LoginTime", item.LoginTime, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name = "password">密码</param>
		/// <return></return>
		public virtual int UpdatePassword(string userId, string password)
		{
			return UpdatePassword(userId, password, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "userId">用户名</param>
		/// <param name = "password">密码</param>
		/// <return></return>
		public virtual int UpdatePassword(string userId, string password, TransactionManager tm = null)
		{
			if (password == null) throw new Exception("password不能为null.");
			const string sql = @"UPDATE [dbo].[Users] SET [Password]=@Password  WHERE [UserId]=@UserId";
			return AdoBase(sql)
							.AddInParameter("@Password", password, DbType.AnsiString, 100)
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name = "nickName">昵称</param>
		/// <return></return>
		public virtual int UpdateNickName(string userId, string nickName)
		{
			return UpdateNickName(userId, nickName, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "userId">用户名</param>
		/// <param name = "nickName">昵称</param>
		/// <return></return>
		public virtual int UpdateNickName(string userId, string nickName, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[Users] SET [NickName]=@NickName  WHERE [UserId]=@UserId";
			return AdoBase(sql)
							.AddInParameter("@NickName", nickName != null ?  (object)nickName : DBNull.Value, DbType.String, 50)
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name = "phone">电话</param>
		/// <return></return>
		public virtual int UpdatePhone(string userId, string phone)
		{
			return UpdatePhone(userId, phone, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "userId">用户名</param>
		/// <param name = "phone">电话</param>
		/// <return></return>
		public virtual int UpdatePhone(string userId, string phone, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[Users] SET [Phone]=@Phone  WHERE [UserId]=@UserId";
			return AdoBase(sql)
							.AddInParameter("@Phone", phone != null ?  (object)phone : DBNull.Value, DbType.AnsiString, 20)
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name = "email">邮箱地址</param>
		/// <return></return>
		public virtual int UpdateEmail(string userId, string email)
		{
			return UpdateEmail(userId, email, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "userId">用户名</param>
		/// <param name = "email">邮箱地址</param>
		/// <return></return>
		public virtual int UpdateEmail(string userId, string email, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[Users] SET [Email]=@Email  WHERE [UserId]=@UserId";
			return AdoBase(sql)
							.AddInParameter("@Email", email != null ?  (object)email : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name = "recTime">创建时间</param>
		/// <return></return>
		public virtual int UpdateRecTime(string userId, DateTime recTime)
		{
			return UpdateRecTime(userId, recTime, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "userId">用户名</param>
		/// <param name = "recTime">创建时间</param>
		/// <return></return>
		public virtual int UpdateRecTime(string userId, DateTime recTime, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[Users] SET [RecTime]=@RecTime  WHERE [UserId]=@UserId";
			return AdoBase(sql)
							.AddInParameter("@RecTime", recTime, DbType.DateTime, 8)
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "userId">用户名</param>
		/// <param name = "loginTime">最后一次登录时间</param>
		/// <return></return>
		public virtual int UpdateLoginTime(string userId, DateTime loginTime)
		{
			return UpdateLoginTime(userId, loginTime, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "userId">用户名</param>
		/// <param name = "loginTime">最后一次登录时间</param>
		/// <return></return>
		public virtual int UpdateLoginTime(string userId, DateTime loginTime, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[Users] SET [LoginTime]=@LoginTime  WHERE [UserId]=@UserId";
			return AdoBase(sql)
							.AddInParameter("@LoginTime", loginTime, DbType.DateTime, 8)
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 按自定义条件更新数据
		/// </summary>
		/// <param name = "set">更新列</param>
		/// <param name = "where">更新条件</param>
		/// <param name = "paras">参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Update(string set, string where, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			if (string.IsNullOrEmpty(set)) throw new ArgumentNullException("set");
			var sql = string.Format(@"UPDATE [dbo].[Users] SET {0} {1}", set, (string.IsNullOrEmpty(where) ? string.Empty : " WHERE " + where));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region Delete方法集合
		/// <summary>
		/// 按主键删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "userId">用户名</param>
		public int DeleteByPK(string userId, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[Users] WHERE [UserId]=@UserId";
			return AdoBase(sql)
							.AddInParameter("@UserId", userId, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "password">密码</param>
		public int DeleteByPassword(string password, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[Users] WHERE [Password]=@Password";
			return AdoBase(sql)
							.AddInParameter("@Password", password, DbType.AnsiString, 100)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "nickName">昵称</param>
		public int DeleteByNickName(string nickName, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[Users] WHERE [NickName]=@NickName";
			return AdoBase(sql)
							.AddInParameter("@NickName", nickName != null ?  (object)nickName : DBNull.Value, DbType.String, 50)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "phone">电话</param>
		public int DeleteByPhone(string phone, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[Users] WHERE [Phone]=@Phone";
			return AdoBase(sql)
							.AddInParameter("@Phone", phone != null ?  (object)phone : DBNull.Value, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "email">邮箱地址</param>
		public int DeleteByEmail(string email, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[Users] WHERE [Email]=@Email";
			return AdoBase(sql)
							.AddInParameter("@Email", email != null ?  (object)email : DBNull.Value, DbType.AnsiString, 100)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "recTime">创建时间</param>
		public int DeleteByRecTime(DateTime recTime, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[Users] WHERE [RecTime]=@RecTime";
			return AdoBase(sql)
							.AddInParameter("@RecTime", recTime, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "loginTime">最后一次登录时间</param>
		public int DeleteByLoginTime(DateTime loginTime, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[Users] WHERE [LoginTime]=@LoginTime";
			return AdoBase(sql)
							.AddInParameter("@LoginTime", loginTime, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 删除指定条件的记录
		/// </summary>
		/// <param name = "whereClause">自定义删除条件，where子句。如：id=1 and name='aaa'</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Delete(string whereClause, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = string.Format(@"DELETE FROM [dbo].[Users] {0}", (string.IsNullOrEmpty(whereClause) ? string.Empty : " WHERE " + whereClause));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region  自定义方法集合
		#endregion

	}


	#endregion
}
